package com.hzqy.service.weekFree;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.weekFree.WeekFreeDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.WeekFreeVo;

@Service
public class WeekFreeServiceBean extends GenericServiceBean<PmsUserVo,WeekFreeDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private WeekFreeDao weekFreeDao ;
	
	@Override
	public WeekFreeDao getEntityDao() {
		return weekFreeDao;
	}
	
	public int insertWeekFree(WeekFreeVo weekFreeVo){
		return weekFreeDao.insertWeekFreeInfo(weekFreeVo);
	}
	
	public WeekFreeVo getWeekFreeInfo(String f_wwf_userid){
		return weekFreeDao.selectWeekFreeInfoByUserid(f_wwf_userid);
	}
	
	public String getWeekFreeResult(String f_wwf_userid){
		String result = "504";
		WeekFreeVo  weekFreeVo = new WeekFreeVo();
		weekFreeVo = weekFreeDao.selectWeekFreeInfoByUserid(f_wwf_userid);
		if(weekFreeVo == null){
			result = "504";
		}else{
			//weekFreeVo 信息不为空，判断当前时间是否在有效时间范围内
			Date date = new Date();//当前时间
			try {
				Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(weekFreeVo.getF_wwf_starttime());
				Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(weekFreeVo.getF_wwf_endtime());
				if(starttime.getTime() <= date.getTime() && date.getTime() <= endtime.getTime()){
					result = "0";
				}
			} catch (ParseException e) {
				LOG.error("时间信息格式化错误：",e);
			}
		}
		return result;
	}

}
